<?php
    $menus = array(// start root menu
    
    array( // start parent menu
        'name'      =>  'Quản lý sản phẩm',
        'submenu'   =>  array( // start child menu
            array(
                    'name'  =>  'Danh sách sản phẩm',
                    'link'  =>  '/admin/sanpham'
                ),
            array(
                    'name'  =>  'Thêm sản phẩm',
                    'link'  =>  '/admin/sanpham/add'
                )
        ) // end child menu  
    ),
);
// end root menu
$currentRoute = Route::getCurrentRoute()->getPath();

?>

<div class="accordion" id="accordion2">
    <!--danh muc -->
    <div class="accordion-group header-menu">
        <div class="accordion-heading">
          <a class="accordion-toggle">
            <li class="nav-header">Menus</li>
          </a>
        </div>
    </div><!--end danh muc-->
<?php foreach ($menus as $k=>$menu): ?>
    <div class="accordion-group">
        <div class="accordion-heading">
          <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse<?php echo $k?>">
            <li class="nav-header"><?php echo $menu['name']?></li>
          </a>
        </div>
        
        <?php 
            $flag = false;
            $active = '' ;
            $str = '';
            foreach($menu['submenu'] as $submenu){
                if(isset($submenu['link']) && substr($submenu['link'], 1) == $currentRoute ){
                    $class = 'active';
                    if($flag == false){
                        $flag = true;
                    }
                }else{
                    $class = '';
                }
                if($submenu['name'] == 'divider'){
                    
                    $str .= '<li class="divider"></li>';
                }else{

                    $link = URL::to("$submenu[link]");
                    $str .= "<li class='$class'><a href='$link'>$submenu[name]</a></li>";
                }
                
            }?>

        <div id="collapse<?php echo $k?>" class="accordion-body collapse <?php echo $flag ? 'in' : null?>">
          <div class="accordion-inner">
            <ul class="nav nav-list">
              <?php echo $str ?>
            </ul>
          </div>
        </div>
    </div>
<?php endforeach ?>
</div>